<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize: pagesize, total: com_list.all_num }" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" @sendUserSearch="receive_search" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="com_list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection"></el-table-column>
          <el-table-column label="用户信息" min-width="120">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户名：</span>
                  <span>{{ scope.row.nickname }}</span>
                </div>
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.man || "----" }}</span>
                </div>
                <div>
                  <span>联系方式：</span>
                  <span>{{ scope.row.tel || "----" }}</span>
                </div>
                <div>
                  <span>反馈类型：</span>
                  <span>{{ scope.row.types || "----" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="上传凭证" min-width="120">
            <template slot-scope="scope">
              <div style="
                                display: flex;
                                flex-wrap: nowrap;
                                justify-content: flex-start;
                                align-items: center;">
                <div style="width: 30%;margin-right: 10px;" v-for="(img, i) in scope.row.image" :key="i">
                  <img :src="$fnc.getImgUrl(img)" @click="getImg(img)" alt />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="反馈内容" min-width="200" prop="content">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>反馈内容：</span>
                  <span>{{ scope.row.content || "----" }}</span>
                </div>
                <div>
                  <span>回复内容：</span>
                  <span>{{ scope.row.reply || "----" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="是否审核" min-width="130" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_check" active-color="#13ce66" inactive-color="#ffffff" active-text="审核" inactive-text="未审核" active-value="1" @change="getIskeck($event, scope.row)" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="提交时间" min-width="150">
            <template slot-scope="scope">{{
              scope.row.created_time | getTimeFormat
            }}</template>
          </el-table-column>
          <el-table-column label="操作" min-width="80">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button>
              <el-button type="danger" size="mini" @click="del_com(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="deleteAll_com">删除</a>
      </template>
    </tableComponents>
    <el-dialog :close-on-click-modal="false" title="编辑" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="live_single" ref="form" label-width="120px">
        <el-form-item label="回复内容：">
          <el-col :span="18">
            <el-input type="textarea" :rows="6" clearable placeholder="请输入" v-model="live_single.reply" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="editlive(live_single)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="图片信息" :visible.sync="dio">
      <img :src="$fnc.getImgUrl(piclink)" alt />
    </el-dialog>
  </div>
</template>
<script>
import { userComplaintSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  name: "complaint",
  data() {
    return {
      is_edit: false,
      dialogFormVisible: false,
      live_single: {
        reply: "",
      },

      userSearchData: userComplaintSearchData,
      dio: false,
      piclink: "",
      multipleSelection: [],
      image: [],
      serarch_from: {},
      is_search: false,
      loading: false,
      com_list: {},
      currentPage: 1, //初始页
      pagesize: 10, //    每页的数据
    };
  },

  created() {
    this.get_com_list(1);
    this.get_pro_option();
  },
  methods: {
    editlive(item) {
      var params = {};

      if (this.is_edit == false) {
      } else {
        params = item;
        this.$api.getUser.saveeditcomplaint(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.get_com_list();
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn(item) {
      this.is_edit = true;
      this.live_single = item;
      this.dialogFormVisible = true;
    },
    get_pro_option() {
      this.$api.getUser.get_pro_option({}).then((res) => {
        if (res.data.code == 200) {
          this.$store.commit("setUserComplaintType", res.data.result);
        }
      });
    },
    getIskeck(val, row) {
      var params = {};
      params.id = row.id;
      params.is_check = val;
      this.updata(params);
    },
    updata(row) {
      var params = {};
      params = row;
      this.$api.getUser.saveeditcomplaint(params).then((res) => {
        if (res.data.status == 1 && res.data.code != 200) {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    getImg(src) {
      this.piclink = src;
      this.dio = true;
    },
    deleteAll_com(del_id) {
      //批量删除

      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
            this.$api.getUser.del_complaint({ id_str: str }).then((res) => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", "您已经删除了这条信息。", "success");
                this.get_com_list();
              } else {
                this.$swal("删除失败！", "出错啦！", "success");
                this.get_com_list();
              }
            });
          }
        });
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    del_com(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getUser.del_complaint({ id_str: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.get_com_list();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
              this.get_com_list();
            }
          });
        }
      });
    },
    receive_search(val) {
      this.serarch_from = val;
      this.search_com_list(1);
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      //每页下拉显示数据
      this.pagesize = size;
      this.get_com_list(1);
    },
    handleCurrentChange: function (currentPage) {
      //点击第几页
      this.currentPage = parseInt(currentPage);
      if (this.is_search) {
        //是搜索
        this.get_com_list(this.currentPage);
      } else {
        //不是搜索
        this.get_com_list(this.currentPage);
      }
    },
   search_com_list(page) {
      this.loading = true;
      var params = this.serarch_from;
      params.page = page;
      params.page_size = this.pagesize;
      this.$api.getUser.get_complaint(params).then((res) => {
        if (res.data.code == 200) {
          res.data.result.data.forEach((item) => {
            if (item.piclink) {
              item.image = item.piclink.split("@");
            } else {
              item.image = [];
            }
          });
          this.com_list = res.data.result;
          this.loading = false;
        } else {
          this.$fnc.alerterror(res.data.result);
          this.loading = false;
        }
      });
    },
    get_com_list(page) {
      var params = this.serarch_from || {};
      params.page = page;
      params.page_size = this.pagesize;
      this.loading = true;
      this.$api.getUser.get_complaint(params).then((res) => {
        if (res.data.code == 200) {
          res.data.result.data.forEach((item) => {
            if (item.piclink) {
              item.image = item.piclink.split("@");
            } else {
              item.image = [];
            }
          });
          this.com_list = res.data.result;
          this.loading = false;
        } else {
          this.$fnc.alerterror(res.data.result);
          this.loading = false;
        }
      });
    },
  },
  watch: {
    com_list(old, after) {},
  },
};
</script>
<style scoped></style>
